package com.kkb.service.impl;

import com.kkb.config.UserInfo;
import com.kkb.mapper.TbSysuserMapper;
import com.kkb.pojo.TbSysuser;
import com.kkb.pojo.TbSysuserExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Component;
import org.springframework.util.AntPathMatcher;

import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @author: sx_wuy
 * @time: 2020/6/16 21:34
 * @Version 1.0
 */

@Component("rbacService")
public class UserDetailsServiceImpl implements UserDetailsService {

    @Autowired
    private TbSysuserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
        TbSysuserExample example = new TbSysuserExample();
        TbSysuserExample.Criteria criteria = example.createCriteria();
        criteria.andUsernameEqualTo(username);
        List<TbSysuser> users = userMapper.selectByExample(example);

        if(users.size() != 0){
            String name = users.get(0).getUsername();
            String password = users.get(0).getPassword();

            UserInfo userInfo=new UserInfo(name, password, "ROLE_ADMIN", true,true,true, true);
            return userInfo;
        }else
            return null;
    }
}
